<?php
class EquipmentUnit extends ORDataObject {
	var $equipment_unit_id	= '';
	var $vi_name	=	'';
	var $en_name	=	'';
	
	var $_table 		= 'equipment_unit';
	var $_key 			= 'equipment_unit_id';
	var $_internalName	= 'EquipmentUnit';
	const EQUIPMENT_ID = 9;
	function EquipmentUnit() {
		parent::ORDataObject();
	}
	
	function getAll(){
		$field	=	L10nHelper::getLocale();
		$field 	=	L10nHelper::changeField($field, "name");
		$ds = new Datasource_sql();
		$sql = array(
					'cols'	=> "equipment_unit_id, $field",
					'from'	=> " $this->_table"
					);
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
	//TODO: Localization
	function getL10nKeyByName($name){
		$field	=	L10nHelper::getLocale();
		$field	=	L10nHelper::changeField($field, "name");
		$sql	=	"SELECT $field name FROM $this->_table WHERE $field='$name'";
		$res	=	$this->_execute($sql);
		if($res && !$res->EOF){
			return $res->fields['name'];
		}
		// Add new unit
		$supported	=	L10nHelper::getSupportedLocales();
		$data		=	array();
		foreach ($supported as $locale=> $country){
			$locale = L10nHelper::changeField($locale, "name");
			$data[$locale]	=	$name;
		}
	
		$objUnit	=	Celini::newORDO('EquipmentUnit');
		$objUnit->populateArray($data);
		$objUnit->persist();
		return $id;
	}

}
?>